package solution.liuyu2783.offer;

import java.util.Arrays;

/**
 * 剑指 Offer 21. 调整数组顺序使奇数位于偶数前面
 */
public class Q21_Exchange_E {

    public static int[] exchange(int[] nums) {
        if(nums.length == 0){
            return nums;
        }
        int i = 0;
        int j = nums.length-1;
        while (i <j){
            int vi = nums[i];
            if(vi%2 ==1){
                i++;
            }else {
                int temp = nums[j];
                nums[j] = vi;
                nums[i] = temp;
                j--;
            }
        }
        return nums;
    }

    public static void main(String[] args) {
        int[] x = {1,2,3,4};
        System.out.println(Arrays.toString(exchange(x)));
    }
}
